home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 October: Mac OS SDK / Dev.CD Oct 97 SDK2.toast / Development Kits (Disc 2) / ScriptX / Documentation / Code Examples from Docs / langguid / chap_04 / xmpl_03.sx < prev    next >
Encoding:
Text File  |  1996-05-21  |  1.4 KB  |  64 lines  |  [TEXT/ttxt]

  1. --<<<
  2. -- Kaleida Labs, Inc.
  3. -- Field Guide to the ScriptX Language
  4. -- chapter 4, example 3
  5.  
  6. -- create a module to avoid naming conflicts
  7. module Scratch15 uses ScriptX end
  8. in module Scratch15
  9.  
  10. -- declare globals and make sure they aren't defined already
  11. global i, j, k, x
  12.  
  13. -- for loop examples
  14. for 9 do print "hello" 
  15.  
  16. global allSpaces := #()
  17. for 52 do append allSpaces ""
  18.  
  19. global theMin := 100
  20. for i := #(1, 435, 234, 23, 8) do 
  21.     if i < theMin do theMin := i
  22. theMin
  23.  
  24. -- examples with ranges
  25. for i := 1 to 23 do print i 
  26. for i in 0 to 100 by 10 do print (i * i) 
  27.  
  28. -- decreasing ranges
  29. for i := 10 to 1 do print (i + i) 
  30.  
  31. -- collections as sources of iteration
  32. for i in #(1,2,3,4) do print i 
  33. for i := #("Francois","Inez","Louis","Margot") do 
  34.     format debug "%* did it!\n" i @unadorned
  35.  
  36. global countdown := 10 to 1
  37. for i in countdown do
  38.     (format debug "%* seconds to blast off!\n" i @normal)
  39.  
  40. -- multiple sources of iteration
  41. for 14, i := 1 to 1000 by 23 do
  42.         (prin i @normal debug; prin " " @unadorned debug)
  43.  
  44. for 14, i := 1 to 1000 by 230 do
  45.         (prin i @normal debug; prin " " @unadorned debug)
  46.  
  47. for i := 1 to 10, j := 1 to 10 by 2 do 
  48. (
  49.     format debug "I is %1. J is %2\n" #(i, j) #(@normal,@normal)
  50.     print (i * j) 
  51. )
  52.  
  53. global x := 1
  54. for 23 while x <= 5 do (
  55.     print x
  56.     x := x + 1
  57. )
  58.  
  59. for j := 1 to 100, k := 1 to 100 by 5 while j * k * k < 10000 do (
  60.     prin j @normal debug; prin ", " @unadorned debug
  61.     prinln k @normal debug
  62. )
  63. -->>>
  64.